﻿using System.Collections.Generic;
using Aluetjen.EmailService.Domain.Models.Message;
using Aluetjen.EmailService.Domain.Models.Pipeline;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Aluetjen.EmailService.Domain.Tests.Models.Pipeline
{
    [TestClass]
    public class RedirectionTests
    {
        [TestMethod]
        public void Redirect_Should_Set_To()
        {
            const string newreceipientLuetjenIe = "NewReceipient@luetjen.ie";
            var redirection = new Redirection
                                  {
                                      RedirectTo = new MailAddress{Address = newreceipientLuetjenIe}
                                  };

            var message = new MailMessage
                              {
                                  To = new List<MailAddress>{new MailAddress{Address = "OldReceipient@luetjen.ie"}}
                              };

            redirection.TransformMessage(message);

            Assert.AreEqual(newreceipientLuetjenIe, message.To[0].Address);
            Assert.AreEqual(1, message.To.Count);
        }
        
        [TestMethod]
        public void Redirect_Should_Clear_Cc()
        {
            var redirection = new Redirection
            {
                ClearCc = true
            };

            var message = new MailMessage
            {
                CC = new List<MailAddress> { new MailAddress { Address = "OldReceipient@luetjen.ie" } }
            };

            redirection.TransformMessage(message);

            Assert.AreEqual(0, message.CC.Count);
        }

        [TestMethod]
        public void Redirect_Should_Clear_Bcc()
        {
            var redirection = new Redirection
            {
                ClearBcc = true
            };

            var message = new MailMessage
            {
                Bcc = new List<MailAddress> { new MailAddress { Address = "OldReceipient@luetjen.ie" } }
            };

            redirection.TransformMessage(message);

            Assert.AreEqual(0, message.Bcc.Count);
        }
    }
}
